import 'dart:async';

import 'package:bashu/CenterPage/center_page.dart';
import 'package:bashu/HomePage/home_page.dart';
import 'package:bashu/ProfilePage/profile_page.dart';
import 'package:bashu/ShopPage/shop_page.dart';
import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

Map<String, String> _bottomNames = {
  "home": "艺典",
  "center": "创艺",
  "shop": "艺淘",
  "profile": "本艺"
};

class _HomeState extends State<Home> {
  int currentIndex = 0;
  List<BottomNavigationBarItem> _bottomNavigationBarItemList = [];
  List<Widget> pageList = [
    HomePage(),
    CenterPage(),
    ShopPage(),
    ProfilePage(),
  ];

  void _onTapClick(int index) {
    setState(() {
      currentIndex = index;
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _bottomNames.forEach((assetsName, barName) {
      _bottomNavigationBarItemList
          .add(_bottomNavigationBarItem(assetsName, barName));
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: pageList[currentIndex],
      bottomNavigationBar: BottomNavigationBar(
          items: _bottomNavigationBarItemList,
          currentIndex: currentIndex,
          onTap: _onTapClick,
          unselectedItemColor: Colors.black,
          selectedItemColor: Colors.amber[900]),
    );
  }
}

BottomNavigationBarItem _bottomNavigationBarItem(
    String assetsName, String barName) {
  return BottomNavigationBarItem(
    icon: Image.asset(
      "assets/icons/tabBar_${assetsName}.png",
      width: 24,
      height: 24,
    ),
    activeIcon: Image.asset(
      "assets/icons/tabBar_active_${assetsName}.png",
      width: 24,
      height: 24,
    ),
    label: barName,
  );
}
//
// Widget _myWidget (){
//   return MaterialButton(onPressed: )
// }
